<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
	<view class="paryorder-content">
		<!-- 这里设置了z-paging加载时禁止自动调用reload方法，自行控制何时reload（懒加载）-->
		<!--  :enable-back-to-top="currentIndex===tabIndex" 在微信小程序上可以多加这一句，因为默认是允许点击返回顶部的，但是这个页面有多个scroll-view，会全部返回顶部，所以需要控制是当前index才允许点击返回顶部 -->
		<z-paging ref="paging" v-model="dataList" @query="queryList" :fixed="false" :auto="true">
			<view class="" slot="top" style="background-color: #F8F8F8;">
				<view class="u-p-20" style="background-color: #F8F8F8;">
					<u-search :searchIconFlag="true" v-model="searchText" input-align="center" placeholder="合同号搜索" height="70" :border-color="'#FFBB1A'" :bg-color="'#F8F8F8'" 	:show-action="false" @change="reloadFn" @search="reloadFn"></u-search>
				</view>
			</view>
			<!-- 如果希望其他view跟着页面滚动，可以放在z-paging标签内 -->
			<view class="payorder-container" v-for="(item,index) in dataList" :key="index" >
				<view class="payorder-section">
						<view class="section-list ">
						<view class="section-item u-m-l-18">
							<view class="u-flex" style="width:100%;margin-bottom: 20rpx;">
								<view class="section-item-name  u-flex" style="flex-wrap: wrap;">
									<text class="u-font-10 u-p-8" style=" background-color: #ff551a; color: #fff;border-radius: 10rpx;">
										合同号
									</text>
									<text class="u-m-l-10">
										{{item.contractNo}}
									</text>
								</view>
								
							</view>
							<view class="u-flex">
								<view class="section-item-count u-m-r-10" >附件数量：{{item.resourcesCount}}</view>
								
								<view class="section-item-count u-m-l-10">明细数量：{{item.itemsCount}}</view>
							</view>
						</view>
					</view>
					<view class="u-flex u-col-center u-row-between u-m-l-20" style="height: 100%;">
						<view class="section-btn-box u-m-r-40" @click="$mRouter.push({route:'/pages/owners/billofEntryMange/editBillofEntry?type=edit&id='+item.id})">
							<image src="/static/owners/editContract.png" mode="" style="height: 46rpx;width: 46rpx;"></image>
						</view>
						<view class="section-btn-box" @click="delTemplateTap(item.id)">
							<image src="/static/xiaoshou/delPrice.png" mode="" style="height: 46rpx;width: 46rpx;" ></image>
						</view>
					
					</view>
				</view>
			</view>
		</z-paging>
		<u-modal v-model="delModel" :content="'您确定要移除此条数据吗？'" ref="delModel" :async-close="true"  @confirm="delTemplateFn()" ></u-modal>
	</view>
</template>

<script>
	import { useShopStore } from '@/store/shop.js';
	import { mapState } from 'pinia';
	export default {
		data() {
			return {
				//v-model绑定的这个变量不要在分页请求结束中自己赋值！！！
				dataList: [],
				searchText:'',
				delModel:false,
				delContractId:'',
			}
		},
		computed:{
			...mapState(useShopStore, {storeShop: 'shop'})
		},
		methods: {
			reloadFn(){
				this.$refs.paging.reload();
			},
			editContractBtnTapFn(item){
				
			},
		
			// 删除按钮点击
			delTemplateTap(id){
				this.delContractId = id;
				this.delModel = true;
			},
			// 删除价格级别
			async delTemplateFn(){
				uni.showLoading({
					title:"loading..."
				})
				const res = await this.$newHttp.delete('api/Product/DeleteDockReceipt?dockReceiptId='+this.delContractId);
				console.log(res);
				uni.hideLoading();
				if(res.code === 200){
					uni.showToast({
						title:'删除成功',
					});
					this.delModel = false;
					this.$refs.paging.reload();
				}else{
					this.$u.toast('删除失败');
				}
			},
			async queryList(pageNo, pageSize) {
				//组件加载时会自动触发此方法，因此默认页面加载时会自动触发，无需手动调用
				//这里的pageNo和pageSize会自动计算好，直接传给服务器即可
				//模拟请求服务器获取分页数据，请替换成自己的网络请求
				const params = {
					pageIndex: pageNo,
					pageSize: pageSize,
					brandownerId:this.storeShop.id,
				}
				if(this.searchText!==''){
					params.contractNo = this.searchText;
				}
				uni.showLoading({
					title: '加载中...',
					mask: false
				});
				const res = await this.$newHttp.get('api/Product/GetPagedDockReceiptByContractNo', {params:params} );
				uni.hideLoading({
					title: '加载中...'
				})
				if(res.code === 200){
					this.$refs.paging.complete(res.data.list);
				}else{
					this.$refs.paging.complete(false);
				}
			},
			itemClick(item) {
				console.log('点击了', item.title);
				this.$mRouter.push({ 
					route: '/pages/sale/payorder/createPayOrder?shop='+item.id,
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	/* 注意:父节点需要固定高度，z-paging的height:100%才会生效 */
	.paryorder-content {
		height: 100%;
	}
	.payorder-container{
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 30rpx;
		.payorder-header{
			display: flex;
			justify-content: space-between;
		}
		.payorder-section{
			display: flex;
			align-items: center;
			box-sizing: border-box;
			padding: 35rpx 0;
			margin-bottom: 20rpx;
			.section-image{
				width: 80rpx;
				height: 80rpx;
				display: block;
				border-radius: 50%;
				margin-right: 32rpx;
			}
			.section-list{
				flex: 1;
				overflow: hidden;
				// margin-left: 20rpx;
				.section-btn{
					width: 160rpx;
					margin-left: 10rpx;
					height:70rpx;
					border-radius: 35rpx;
					border: 1rpx solid #FFBB1A;
					color: #FFBB1A;
					text-align: center;
					line-height: 70rpx;
				}
				.section-btn-disabled{
					border-color:#999999;
					color: #999999;
				}
				.section-item{
					width: 100%;
					.section-item-name{
						font-size: 32rpx;
						font-weight: 500;
					}
					.section-item-count{
						font-size: 24rpx;
						color: #999;
					}
					
				}
			}
			.section-btn-box{
				display: flex;
				flex-direction: column;
				justify-content: center;
				align-items: center;
				>.btn-text{
					font-size: 20rpx;
					margin-top: 10rpx;
				}
			}
			
		}
		
	}


</style>
